package com.kotlin.demo.helper

import com.kotlin.demo.constant.Constants
import com.kotlin.demo.enums.DialogType
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 弹窗管理类
 */
object DialogHelper {
    /**
     * 关闭所有弹窗
     */
    fun dismissDialog() {
        Constants.isShowDialog.value = false
    }

    /**
     * 显示提示弹窗
     */
    fun showTipsDialog(tipsContent: String) {
        if (tipsContent.trim() == "") {
            return
        }
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.TOAST
        Constants.tipsContent.value = tipsContent
        Constants.mainScope.launch(Dispatchers.Default) {
            delay(800L)
            dismissDialog()
        }
    }

    /**
     * 显示提示弹窗
     */
    fun showTipsDialog(tipsContent: String, back: () -> Unit) {
        if (tipsContent.trim() == "") {
            return
        }
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.TOAST
        Constants.tipsContent.value = tipsContent
        Constants.mainScope.launch(Dispatchers.Default) {
            delay(800L)
            dismissDialog()
            delay(100L)
            back()
        }
    }

    /**
     * 显示添加路径弹窗
     */
    fun showAddResDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.ADD_PATH
    }

    /**
     * 加载中弹窗
     */
    fun showLoadingDialog(tipsContent: String) {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.LOADING
        Constants.tipsContent.value = tipsContent
    }

    /**
     * 写入多语言编辑key 弹窗
     */
    fun showEditKeyDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.EDIT_KEY
    }

    /**
     * 替换多语言 弹窗
     */
    fun showReplaceKeyDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.REPLACE_KEY
    }

    /**
     * 移除多语言 弹窗
     */
    fun showRemoveKeyDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.REMOVE_KEY
    }

    /**
     * 预览多语言 编辑key 弹窗
     */
    fun showFindKeyDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.SHOW_KEY
    }

    /**
     * 导出多语言弹窗
     */
    fun showExportDialog() {
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.EXPORT
    }
    fun showEditLanguageConfigDialog(){
        Constants.isShowDialog.value = true
        Constants.dialogType.value = DialogType.EDIT
    }
}